//---------------------------------------------------------------------------

#ifndef CIISClientInterfaceH
#define CIISClientInterfaceH

#include "CIISDB.h"
#include "DebugWinU.h"
#include "CIISNetInterface.h"
#include "CIISServerInterface.h"
#include <scktcomp.hpp>
#include "CIIServerSocket.h"

//---------------------------------------------------------------------------

class TCIISClientInterface : public TObject
{
private:
  TCIISDBModule *DB;
  TDebugWin *DW;
  TCIISNetInterface *NetInt;
  TCIISServerInterface *SerInt;
  CIISServerMode ServerMode;
  int PortNoLocal, PortNoRemote, PortNoPM;
	TCIIServerSocket *LSocket, *RSocket, *PMSocket, *CurrSocket;
	TCamurPacket  *PMReply, *MReply;
	TTimer *TimerSM;
	TDateTime TOutSM;
	bool SelectPrjRunning,
			 PMLoggInRunning, PMLoggOutRunning, PMExitPrjRunning,
			 MonLoggInRunning, MonLoggOutRunning, MonCancelSyncRunning;
	CIISSelPrjState SelPrjState;
	CIISPMLoggInState PMLoggInState;
	CIISPMLoggOutState PMLoggOutState;
	CIISPMExitPrjState PMExitPrjState;
	CIISMonLoggInState MonLoggInState;
	CIISMonLoggOutState MonLoggOutState;
	CIISMonCancelSyncState MonCancelSyncState;

	String UserLevel, Password, MonUserLevel, MonPassword;


  TLocateOptions NoOpts;

  void __fastcall Debug(String Message);

  bool __fastcall ParseCommands();
  bool __fastcall ParsePMCommands();

  String __fastcall TabSensorsRecord();
  String __fastcall TabPowerSupplyRecord();
  String __fastcall TabRecordingsRecord();
	String __fastcall TabEventLogRecord();
  String __fastcall TabValuesRecord();
  String __fastcall TabValuesLPRRecord();
  String __fastcall TabValuesDecayRecord();
  String __fastcall TabSensorsLastValRecord();
  String __fastcall TabSensorsAlarmRecord();
  String __fastcall TabPowerSupplyLastValRecord();
  String __fastcall TabPowerSupplyAlarmRecord();
  String __fastcall TabProjectRecord();
  String __fastcall TabControllersRecord();
  String __fastcall TabZonesRecord();

	void __fastcall GetLocalMessage();
	void __fastcall GetRemoteMessage();
  void __fastcall GetPMMessage();
	bool __fastcall GetLocalClientConnected();
	bool __fastcall GetPMConnected();
	bool __fastcall GetRemoteClientConnected();
	bool __fastcall SelectPrjIni( String SetUserLevel, String SetPassword );
	void __fastcall SM_SelectPrj();
	bool __fastcall PMLoggInIni();
	void __fastcall SM_PMLoggIn();
	bool __fastcall PMLoggOutIni();
	void __fastcall SM_PMLoggOut();
	bool __fastcall PMExitPrjIni();
	void __fastcall SM_PMExitPrj();
	bool __fastcall MonLoggInIni();
	void __fastcall SM_MonLoggIn();
	bool __fastcall MonLoggOutIni();
	void __fastcall SM_MonLoggOut();
	bool __fastcall MonCancelSyncIni();
	void __fastcall SM_MonCancelSync();

	bool __fastcall SM_Running();


protected:

public:
  __fastcall TCIISClientInterface( TCIISDBModule * SetDB,
                                   TDebugWin * SetDebugWin,
                                   TCIISNetInterface *SetNetInt,
                                   TCIISServerInterface *SetSerInt,
                                   CIISServerMode SetServerMode,
                                   int SetPortNoLocal,
                                   int SetPortNoPM,
                                   int SetPortNoRemote );
  __fastcall ~TCIISClientInterface();
  void __fastcall SetDebugWin(TDebugWin * SetDebugWin);
	void __fastcall TransferRelpy( TCamurPacket *o );
	void __fastcall TimerSMEvent(TObject * Sender);

        void __fastcall Tst1( String DBDir );

__published:
				__property bool LocalClientConnected  = { read=GetLocalClientConnected };
				__property bool PMConnected  = { read=GetPMConnected };
        __property bool RemoteClientConnected  = { read=GetRemoteClientConnected };

};


#endif
